package com.zhuguowei.umdemo.umeng;

import android.app.Activity;
import android.content.Intent;
import android.widget.Toast;

import com.umeng.socialize.PlatformConfig;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;
import com.zhuguowei.umdemo.R;

public class ShareUtils {
	private UMShareAPI mShareAPI;
	private Activity activity;
	public ShareUtils(Activity activity) {
		PlatformConfig.setWeixin("wx8de07681a2b552c6", "20c7863f5cbf39da535ce1cecb2f38f9");
		PlatformConfig.setSinaWeibo("1613692913", "35c7e357354edce73460720cad08df96","https://api.weibo.com/oauth2/default.html");
		PlatformConfig.setQQZone("1106501348", "ddkTzp5zVcBT523a");
		mShareAPI = UMShareAPI.get(activity);   
		this.activity = activity;
//		Config.DEBUG = true;//友盟调试开关 zgw-2017/10/26 10:38
	}
	
	public ShareAction getShareAction(){ 
//		final SHARE_MEDIA[] displaylist = new SHARE_MEDIA[] { SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.SINA, SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE };
//		return new ShareAction(activity).setDisplayList(displaylist).withMedia(new UMImage(activity, R.mipmap.public_logo)).setListenerList(umShareListener);
        //不带面板 zgw-2017/10/26 8:38
		return new ShareAction(activity).withMedia(new UMImage(activity, R.mipmap.public_logo));
	}  
	public ShareAction share2App(SHARE_MEDIA data, String url, String shareTitle, String shareText){
//        UMImage image = new UMImage(ShareActivity.this, "imageurl");//网络图片
//        UMImage image = new UMImage(ShareActivity.this, file);//本地文件
        UMImage image = new UMImage(activity, R.mipmap.public_logo);//资源文件
//        UMImage image = new UMImage(ShareActivity.this, bitmap);//bitmap文件
//        UMImage image = new UMImage(ShareActivity.this, byte[]);//字节流
        //设置压缩图片 zgw-2017/10/26 8:43
        UMImage thumb =  new UMImage(activity, R.mipmap.public_logo);
        image.setThumb(thumb);
        image.compressStyle = UMImage.CompressStyle.SCALE;//大小压缩，默认为大小压缩，适合普通很大的图
//        image.compressStyle = UMImage.CompressStyle.QUALITY;//质量压缩，适合长图的分享
//        压缩格式设置
//        image.compressFormat = Bitmap.CompressFormat.PNG;//用户分享透明背景的图片可以设置这种方式，但是qq好友，微信朋友圈，不支持透明背景图片，会变成黑色

		UMWeb web = new UMWeb(url);
		web.setTitle(shareTitle);//标题
		web.setThumb(image);  //缩略图
		web.setDescription(shareText);//描述

		return new ShareAction(activity).withMedia(web).setPlatform(data).setCallback(umShareListener);
	}
	
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		mShareAPI.onActivityResult(requestCode, resultCode, data);
	}
	
	private UMShareListener umShareListener = new UMShareListener() {

		@Override
		public void onStart(SHARE_MEDIA media) {
//			Toast.makeText(activity, "分享onStart", Toast.LENGTH_SHORT).show();
		}

		@Override
		public void onResult(SHARE_MEDIA media) {
//			Toast.makeText(activity, "分享onResult", Toast.LENGTH_SHORT).show();
		}

		@Override
		public void onError(SHARE_MEDIA media, Throwable throwable) {
//			Toast.makeText(activity, "分享onError", Toast.LENGTH_SHORT).show();
		}

		@Override
		public void onCancel(SHARE_MEDIA media) {
			Toast.makeText(activity, "分享onCancel", Toast.LENGTH_SHORT).show();
		}
	};
}
